<template>
	<view class="mainbgc" v-show="show" style="padding-top: 30rpx;">
		<view class=" flexbetween1 item " v-if="list.data.length" v-for="item in list.data" :key="item.id" @click="goroomdetail(item.id)">
			<view class="flextop">
				<view class="lefimg">
					<image :src="item.image_text"></image>
				</view>
				<view class="tsquare">
					<view class="title">{{item.name}}</view>
					<view class="qure">{{item.attention}}</view>
				</view>
			</view>
			<view>
				<view class="dingImg flexbottom">
					<view class="price">￥{{item.salesprice}}/<text style="font-size: 24rpx;">晚</text></view>
					<image class="ding" src="../../static/images/scenic/ding.png" mode=""></image>
				</view>
			</view>
		</view>
		
		<view class="flexcenter1" v-if="!list.data.length">
			<view class="placeholderimg" style="margin-top: 300rpx;">
				<image src="../../static/images/bg-icons/placeholderimg.png" mode=""></image>
			</view>
			<view class="zanwushuju">暂无数据~</view>
		</view>
		<!-- <view class=" flexbetween1 item " v-for="item in 4">
			<view class="flextop">
				<view class="lefimg">
					<image src="../../static/logo.png"></image>
				</view>
				<view class="tsquare">
					<view class="title">大床房</view>
					<view class="qure">1900m2</view>
				</view>
			</view>
			<view>
				<view class="dingImg flexbottom">
					<view class="price">￥199/<text style="font-size: 24rpx;">晚</text></view>
					<image class="ding" src="../../static/images/scenic/ding.png" mode=""></image>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				start: "", //年月日
				end: "", //年月日
				startime: "", //开始时间
				endtime: "", //结束时间
				startweek: "", //开始周
				endweek: "", //结束周
				daynum: 1,
				
				show:false,
			}
		},
		onLoad() {
			this.init()
			this.dateinit()
		},
		methods: {
			// 热门推荐列表
			init(isPage, page) {
				let _this = this;
				httpRequest.request('api/shop/getTpriceType', 'GET', {
					page: page || 1,
					limit: _this.limit,
				}).then(res => {
					this.show=true
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					this.show=true
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			goroomdetail(id) {
				let date = {
					id,
					start: this.start,
					end: this.end,
					startime: this.startime, //开始时间
					endtime: this.endtime, //结束时间
					startweek: this.startweek, //开始周
					endweek: this.endweek, //结束周
					daynum: this.daynum,
				}
				uni.navigateTo({
					url: '/pages/hotel/roomdetail?msg=' + encodeURIComponent(JSON.stringify(date))
				})
			},
			// 日期初始化
			dateinit() {
				// 今天
				let start = this.date(new Date())
				let end = new Date()
				// 明天
				end.setTime(end.getTime() + 24 * 60 * 60 * 1000);
				end = this.date(end)
				this.start = start
				this.end = end
				this.startime = Number(start[5] + start[6]) + "月" + Number(start[8] + start[9]) + "日" //月日赋值
				this.endtime = Number(end[5] + end[6]) + "月" + Number(end[8] + end[9]) + "日" //月日赋值
				this.startweek = this.weekchange(start) //计算周
				this.endweek = this.weekchange(end) //计算周
				this.daynum = this.DateDiff(start, end) //计算间隔天数
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			// 周转换，此处地date是年月日
			weekchange(date) {
				let weekArrayList = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ]
				let index = new Date(date).getDay()
				let week = weekArrayList[index]
				return week
			},
			// 计算两个日期之间相差天数
			DateDiff(sDate1, sDate2) {
				//sDate1和sDate2是2006-12-18格式
				var aDate1, aDate2, oDate1, oDate2, iDays;
				aDate1 = sDate1.split("-");
				oDate1 = new Date(aDate1[1] + '/' + aDate1[2] + '/' + aDate1[0]);
				aDate2 = sDate2.split("-");
				oDate2 = new Date(aDate2[1] + '/' + aDate2[2] + '/' + aDate2[0]);
				iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);
				return iDays
			}
		}
	}
</script>

<style>
.item:nth-child(1){
	margin:0;
}
</style>